<template>
    <!-- <div>封堵白名单</div> -->
    <a-row>
      <a-col>
        <a-card :bordered="false" style="margin-bottom: 10px">
          <!-- 查询区域 -->
          <div class="search-wrapper-btn">
              <a-button type="link" @click="show = !show">
                <span v-if="!show">展开
                  <a-icon type="down" />
                </span>
                <span v-else>收起
                  <a-icon type="up" />
                </span>
              </a-button>
            </div>
          <div class="table-page-search-wrapper">
            <a-form-model ref="ruleForm" :model="pageFilter" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-row style="display:flex">
                <a-col :span="6">
                <a-form-model-item label="申诉主题">
                    <a-input  placeholder="请输入涉诈地址、域名、ip" v-model="pageFilter.complaintSubject"/>
                </a-form-model-item>
              </a-col>
                <a-col :span="6">
                <a-form-model-item label="涉诈域名" style="margin-left:0px">
                    <a-input  placeholder="请输入涉诈地址、域名、ip" v-model="pageFilter.fraudDomainName"/>
                </a-form-model-item>
                </a-col>
                <a-col :span="6">
                <a-form-model-item label="申诉人" style="margin-left:0px">
                    <a-input  placeholder="请输入涉诈地址、域名、ip" v-model="pageFilter.complainant"/>
                </a-form-model-item>
              </a-col>
                  <a-col :span="6" style="margin-left:0px">
                    <a-space :size="6">
                      <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                      <a-button @click="onResetForm" icon="reload">重置</a-button>
                    </a-space>
                  </a-col>   
              </a-row>
              <a-col :span="6">
                <a-form-model-item label="审批状态"  v-if="show">
                    <a-select style="width:100%" v-model="pageFilter.appealStatus">
                      <a-select-option value=" ">全部</a-select-option>
                      <a-select-option v-for="(item, key) in appealStatus" :key="key" :value="item.value">
                        {{ item.title?item.title:'' }}
                      </a-select-option>
                    </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="6">
                <a-form-model-item label="申诉时间"  v-if="show">
                    <a-range-picker v-model="pageFilter.time"/>
                </a-form-model-item>
              </a-col>
            </a-form-model>
          </div>
        </a-card>
        <a-card :bordered="false">
          <div>
            <a-button type="primary"  style="margin-right:10px">同步</a-button>
            
            <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
              :columns="columns" :dataSource="pageData" @selectedRowKey="onSelectedRow" @change="onTableChange">
              <template slot="action" slot-scope="text, record">
                    <a-button type="link" @click="Approval(record)" v-if="record.status1 == 1">审批</a-button>
                    <a-button type="link" @click="Details(record)" v-if="record.status1 == 2 || record.status1 == 3">详情</a-button>
              </template>
              <template slot="appealTime" slot-scope="text, record">
                    <span>  {{ text?timestampToTime(new Date(text)):'' }} </span>
              </template>
            </z-table>
          </div>
        </a-card>
      </a-col>
    </a-row>
  </template>
  
  <script>
  import { getProcessInfoList } from '@/api/plugging/Police'
  export default {
    mounted () {
      this.onQuery()
    },
    data () {
      return {
        appealStatus:[
          {
            title:'待审批',
            value:1
          },
          {
            title:'通过',
            value:2
          },
          {
            title:'不通过',
            value:3
          },
        ],
        show:false,
        labelCol: { span: 5 },
        wrapperCol: { span: 16 },
        loading: false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        pageData: {},
        columns:[
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '申诉主题',
            dataIndex: 'complaintSubject',
            align: 'center',
          },
          {
            title: '涉诈域名',
            dataIndex: 'fraudDomainName',
            align: 'center',
          },
          {
            title: '申诉原因',
            dataIndex: 'reasonAppeal',
            align: 'center',
          },
          {
            title: '申诉人',
            dataIndex: 'complainant',
            align: 'center',
          },
          {
            title: '申诉时间',
            dataIndex: 'appealTime',
            align: 'center',
            scopedSlots: { customRender: 'appealTime' },
          },
          {
            title: '审批状态',
            dataIndex: 'processStatus',
            align: 'center',
            customRender: text => 
            `${text==1?'待审批':text==2?'审批中':text==3?'通过':text == 4?'不通过':'已撤销'}`
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
          },

        ]
      }
    },
    methods: {
      Approval(record){
        this.$router.push({
        path: '/plugging/police/Approval/Approval',
        query: {
          type:'approval',
          id:record.id1,
          appealTime:record.appealTime,
          complainant:record.complainant,
          complaintSubject:record.complaintSubject,
          documentComplainant:record.documentComplainant,
          fraudDomainName:record.fraudDomainName,
          reasonAppeal:record.reasonAppeal,
        }
      })
      },
      Details(record){
        // console.log(record);
        this.$router.push({
        path: '/plugging/police/Approval/Details',
        query: {
            type:'details',
            id:record.id1,
            appealTime:record.appealTime,
            complainant:record.complainant,
            complaintSubject:record.complaintSubject,
            documentComplainant:record.documentComplainant,
            fraudDomainName:record.fraudDomainName,
            reasonAppeal:record.reasonAppeal,
        }
      })
      },
      onQuery() {
        this.pageFilter.pageNo = 1
        let a = this.pageFilter.time?this.timestampToTime(this.pageFilter.time[0]):''
        let b = this.pageFilter.time?this.timestampToTime(this.pageFilter.time[1]):''
        this.pageFilter.startTime = a
        this.pageFilter.endTime = b
        this.refreshTable()
      },
      //重置
      onResetForm() {
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10,
          departmentId: this.departmentId
        }
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.selectKeys = keys
        this.isDisabled = keys.length > 0 ? false : true
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        this.loading = true
        getProcessInfoList(this.pageFilter).then( res => {
          if (res.success) {
            let a = res.result.records
            res.result.records = []
            a.forEach(item => {
              let b = JSON.parse(item.jsonParam).misblockComplaint;
              b.id1 =item.id
              b.status1 =item.status
              b.processStatus = item.processStatus
              res.result.records.push(b)
            });
            this.pageData = res.result ? res.result : {}
            console.log(this.pageData.records);
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
      timestampToTime(timestamp) {
        if (timestamp === 0 || timestamp == null) {
          return ''
        } else {
          var date = new Date(Date.parse(timestamp))
          var Y = date.getFullYear() + '-'
          var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
          var D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '
          var H = date.getHours() + ':'
          var M2 = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':'
          var S = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
          return Y + M + D + H + M2 + S
        }
      }
    }
  }
  </script>
  
  <style lang="less" scoped>
  .search-wrapper-btn {
    position: absolute;
    right: 8%;
    top: 22px;
    z-index: 100;
  }
  </style>